"""离线脚本-初始化用户"""
'''就是不需要启动项目但又能调用django的、能执行的脚本'''
import init_base
import uuid
import datetime

# 然后就可以 使用django的models了
from web import models
from utils.myencrypt import myMd5
def init_one_user():
    instance = models.UserInfo.objects.create(user_name="admin",email="admin@qq.com",mobile_phone="13877996688",password=myMd5("1"))
    if instance:
        price = models.Price.objects.filter(category=2, title="收费版").first()
        if price:
            models.OrderInfo.objects.create(
                status=2,
                order_num=str(uuid.uuid4()),
                create_user=instance,
                price=price,
                amount=0,
                payment=0,
                start_time=datetime.datetime.now(),
                end_time="2099-12-30 23:59:59",
            )
        else:
            print("==========请先初始化价格策略==============")
    instance2 = models.UserInfo.objects.create(user_name="lism", email="lism@qq.com", mobile_phone="13800008888",password=myMd5("1"))
    if instance2:
        price2 = models.Price.objects.filter(category=1, title="个人免费版").first()
        if price2:
            models.OrderInfo.objects.create(
                status=2,
                order_num=str(uuid.uuid4()),
                create_user=instance2,
                price=price2,
                amount=0,
                payment=0,
                start_time=datetime.datetime.now(),
                end_time="2099-12-30 23:59:59",
            )
        else:
            print("==========请先初始化价格策略==============")

if __name__ == "__main__":
    init_one_user()